
********************************************************************************
********************************************************************************
***************************** THIS IS DO FILE 8 ********************************
******************************* MODEL EXHIBITS *********************************
********************************************************************************
********************************************************************************

cap mkdir `"$output/log/8_model_exhibits"'
cap mkdir `"$output/model_exhibits"'
cap mkdir `"$output/model_exhibits/value_function_figures"'
cap mkdir `"$output/paper_inputs"'

cap log close 
log using `"$output/log/8_model_exhibits/8_model_exhibits.smcl"', replace 


di "This run uses code version from 2023/03/29"


	
********************************************************************************	
********************************************************************************
************* PROBABILITY OF RESUBMISSION AND CONTINUATION VALUE ***************
******************************** FIGURE 3 **************************************
********************************************************************************
********************************************************************************
	
use  `"$output/temp/estimation_data_bin.dta"', clear

// set working directoy to avoid any conflict on BEA server
cd `"$output/paper_inputs"'

// create payer diagnosis FE
gegen PayXDiag = group(pay_type_pooled dx1_code)

// Panel a
// Binscatter of fully dynamic value function
#delimit ;
	binscatter choice_S V_S if n_S!=. & V_S >= -10 & V_S <= 90, n(100) 
	absorb(pay_type_pooled) yscale(range(0 0.6)) ylabel(0(0.2)0.6) 
	xsc(r(-10 70)) xlabel(-10(20)70) line(none) 
	xti("Continuation Value", size(medlarge)) 
	yti("Probability of Resubmission", size(medlarge)) m(Oh) mc(black);
#delimit cr 
graph save  `"binscatter_V_payer_all_groups.gph"',  replace 

// Panel b
// Binscatter of fully dynamic value function with additional Diagnosis FE
#delimit ;
	binscatter choice_S V_S if n_S!=. & V_S >= -10 & V_S <= 90 , n(100) 
	absorb(PayXDiag) yscale(range(0 0.6)) ylabel(0(0.2)0.6) xsc(r(-10 70)) 
	xlabel(-10(20)70) line(none) xti("Continuation Value", size(medlarge)) 
	yti("Probability of Resubmission", size(medlarge)) m(Oh) mc(black);
#delimit cr 
graph save  `"binscatter_V_paydx_all_groups.gph"',  replace

cd "..\..\..\code\main_article"



 
********************************************************************************
********************************************************************************
**************************************** Maps **********************************
************************************** Figure 5 ********************************
********************************************************************************
********************************************************************************

use `"$output/data/regression_data.dta"', clear 

bys payee_state_cd pay_type_pooled: gen visits = _N
cap drop state

gen state = payee_state_cd 

collapse pi CIP lost_revenue tau tau_rf visits, by(pay_type_pooled state)
save `"CIP_state_tables_all_groups.dta"', replace

// set working directoy to avoid any conflict on BEA server
cd `"$output/paper_inputs"'

//maps
maptile CIP if pay_type_pooled==2 , geo(state)  cutv(5(5)30) legdecimals(2)  
graph save `"medicaid_CIP_map.gph"', replace 

maptile CIP if pay_type_pooled==1 , geo(state)  cutv(5(5)30) legdecimals(2)
graph save `"medicare_CIP_map.gph"', replace  

maptile CIP if pay_type_pooled==3 , geo(state)  cutv(5(5)30) legdecimals(2)
graph save `"commercial_CIP_map.gph"', replace 

maptile tau if pay_type_pooled==2 , geo(state)  cutv(0.05(.05).25) legdecimals(2) 
graph save `"medicaid_tau_map.gph"', replace 
 
maptile tau if pay_type_pooled==1 , geo(state)  cutv(0.05(.05).25) legdecimals(2)
graph save `"medicare_tau_map.gph"', replace 

maptile tau if pay_type_pooled==3 , geo(state)  cutv(0.05(.05).25) legdecimals(2)
graph save `"commercial_tau_map.gph"', replace 


cd "..\..\..\code\main_article"


log close 
